home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / ODFDev / Draw / Sources / TextShp.cpp < prev    next >
Encoding:
Text File  |  1996-12-16  |  7.5 KB  |  285 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                TextShp.cpp
  4. //    Release Version:    $ ODF 3 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "ODFDraw.hpp"
  13.  
  14. #ifndef BASESHP_H
  15. #include "BaseShp.h"
  16. #endif
  17.  
  18. #ifndef BOUNDSHP_H
  19. #include "BoundShp.h"
  20. #endif
  21.  
  22. #ifndef TEXTSHP_H
  23. #include "TextShp.h"
  24. #endif
  25.  
  26. #ifndef UTILS_H
  27. #include "Utils.h"
  28. #endif
  29.  
  30. #ifndef CONSTANT_H
  31. #include "Constant.h"
  32. #endif
  33.  
  34. #ifndef DRAWPART_H
  35. #include "DrawPart.h"
  36. #endif
  37.  
  38. #ifndef DRAWPART_H
  39. #include "DrawPart.h"
  40. #endif
  41.  
  42. #ifndef DRAWFRM_H
  43. #include "DrawFrm.h"
  44. #endif
  45.  
  46. #ifndef DRAWPRXY_H
  47. #include "DrawPrxy.h"
  48. #endif
  49.  
  50. #ifndef DRAWLINK_H
  51. #include "DrawLink.h"
  52. #endif
  53.  
  54. #ifndef DRAWCLIP_H
  55. #include "DrawClip.h"
  56. #endif
  57.  
  58. // ----- Part Layer -----
  59.  
  60. #ifndef FWFRMING_H
  61. #include "FWFrming.h"
  62. #endif
  63.  
  64. #ifndef FWUTIL_H
  65. #include "FWUtil.h"
  66. #endif
  67.  
  68. #ifndef FWSELECT_H
  69. #include "FWSelect.h"
  70. #endif
  71.  
  72. #ifndef FWITERS_H
  73. #include "FWIters.h"
  74. #endif
  75.  
  76. // ----- OS Layer -----
  77.  
  78. #ifndef FWEVENT_H
  79. #include "FWEvent.h"
  80. #endif
  81.  
  82. #ifndef FWRECSHP_H
  83. #include "FWRecShp.h"
  84. #endif
  85.  
  86. #ifndef FWTXTBOX_H
  87. #include "FWTxtBox.h"
  88. #endif
  89.  
  90. #ifndef FWLINSHP_H
  91. #include "FWLinShp.h"
  92. #endif
  93.  
  94. #ifndef FWOVLSHP_H
  95. #include "FWOvlShp.h"
  96. #endif
  97.  
  98. #ifndef FWRRCSHP_H
  99. #include "FWRRcShp.h"
  100. #endif
  101.  
  102. #ifndef FWODGEOM_H
  103. #include "FWODGeom.h"
  104. #endif
  105.  
  106. #ifndef FWGRUTIL_H
  107. #include "FWGrUtil.h"
  108. #endif
  109.  
  110. // ----- Foundation Includes -----
  111.  
  112. #ifndef FWSTREAM_H
  113. #include "FWStream.h"
  114. #endif
  115.  
  116. // ----- OpenDoc Includes -----
  117.  
  118. #ifndef SOM_ODTransform_xh
  119. #include <Trnsform.xh>
  120. #endif
  121.  
  122. //========================================================================================
  123. // Runtime Information
  124. //========================================================================================
  125.  
  126. #ifdef FW_BUILD_MAC
  127. #pragma segment odfdrawshapes
  128. #endif
  129.  
  130. //========================================================================================
  131. // RunTime Info
  132. //========================================================================================
  133.  
  134. FW_DEFINE_AUTO(CTextShape)
  135. FW_DEFINE_CLASS_M1(CTextShape, CBoundedShape)
  136.  
  137. const FW_ClassTypeConstant LTextShape = FW_TYPE_CONSTANT('s','h','t','x');
  138. FW_REGISTER_ARCHIVABLE_CLASS(LTextShape, CTextShape, CTextShape::Read, 0, 0, CBaseShape::Write)
  139.  
  140. //========================================================================================
  141. // class CTextShape
  142. //========================================================================================
  143.  
  144. //----------------------------------------------------------------------------------------
  145. // CTextShape::CTextShape
  146. //----------------------------------------------------------------------------------------
  147.  
  148. CTextShape::CTextShape(CDrawPart* drawPart) :
  149.     CBoundedShape(drawPart, kTextShape, kFrameOnly),
  150.     fText
  151. (
  152. "\"Young man\", said the Russian playwright Anton Chekhov, "
  153. "\"I see a brilliant future written on your face.\" "
  154. "These words were spoken to Serge Rachmaninoff."
  155. )
  156. {
  157.     FW_END_CONSTRUCTOR
  158. }
  159.  
  160. //----------------------------------------------------------------------------------------
  161. // CTextShape::CTextShape
  162. //----------------------------------------------------------------------------------------
  163.  
  164. CTextShape::CTextShape(CDrawPart* drawPart, FW_CReadableStream& archive) :
  165.     CBoundedShape(drawPart, archive)
  166. {
  167.     archive >> fText;
  168.     FW_END_CONSTRUCTOR
  169. }
  170.  
  171. //----------------------------------------------------------------------------------------
  172. // CTextShape::~CTextShape
  173. //----------------------------------------------------------------------------------------
  174.  
  175. CTextShape::~CTextShape()
  176. {
  177.     FW_START_DESTRUCTOR
  178. }
  179.  
  180. //----------------------------------------------------------------------------------------
  181. // CTextShape::RenderShape
  182. //----------------------------------------------------------------------------------------
  183.  
  184. void CTextShape::RenderShape(Environment* ev, ODFacet* facet, FW_CGraphicContext& gc)
  185. {
  186. FW_UNUSED(ev);
  187. FW_UNUSED(facet);
  188.     // Draw a frame
  189.     FW_CRect rect = GetRectGeometry();
  190.     AdjustRectForPenSize(rect, GetPenSize());
  191.  
  192.     if (HasFrameStyle())
  193.         FW_CRectShape::RenderRect(gc, rect, FW_kFrame, fFrameInk, fFrameStyle);
  194.  
  195.     // Draw the text
  196.     FW_CFont font(FW_GetTimesFontName(), FW_kPlain, FW_IntToFixed(12));
  197.  
  198.     FW_Fixed halfPenSize = FW_Half(GetPenSize() + FW_kFixedPos1);
  199.     rect.Inset(FW_IntToFixed(2) + halfPenSize, FW_IntToFixed(2) + halfPenSize);
  200.     FW_TextBoxOptions options = FW_kTextBoxJustifyHCenter | FW_kTextBoxWordWrap | FW_kTextBoxWordBreak | FW_kTextBoxClipToBox;
  201.     FW_CTextBoxShape::RenderTextBox(gc, fText, rect, font, options, fFrameInk);
  202. }
  203.  
  204. //----------------------------------------------------------------------------------------
  205. // CTextShape::HitTest
  206. //----------------------------------------------------------------------------------------
  207.  
  208. FW_Boolean CTextShape::HitTest(Environment *ev, FW_CGraphicContext& gc, const FW_CMouseEvent& theMouseEvent) const
  209. {
  210.     FW_CPoint mouse = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  211.     ODFacet* facet = theMouseEvent.GetFacet(ev);
  212.     FW_CFrame* frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
  213.     frame->GetContentView(ev)->FrameToViewContent(ev, mouse);
  214.     
  215.     FW_CTextBoxShape textShape(fText, GetRectGeometry());
  216.     return textShape.HitTest(gc, mouse, FW_IntToFixed(2));
  217. }
  218.  
  219. //----------------------------------------------------------------------------------------
  220. // CTextShape::OutlineShape
  221. //----------------------------------------------------------------------------------------
  222.  
  223. void CTextShape::OutlineShape(FW_CGraphicContext& gc, const FW_CInk& ink, const FW_CStyle& style, const FW_CRect& rect)
  224. {
  225.     FW_CRectShape::RenderRect(gc,
  226.                               rect,
  227.                               FW_kFrame,
  228.                               ink, style);
  229. }
  230.  
  231. //----------------------------------------------------------------------------------------
  232. // CTextShape::CalcClipShape
  233. //----------------------------------------------------------------------------------------
  234.  
  235. ODShape* CTextShape::CalcClipShape(Environment *ev)
  236. {
  237.     return ::FW_NewODShape(ev, GetRectGeometry());
  238. }
  239.  
  240. //----------------------------------------------------------------------------------------
  241. // CTextShape::CreateShapeOutline
  242. //----------------------------------------------------------------------------------------
  243.  
  244. ODShape* CTextShape::CreateShapeOutline(Environment *ev)
  245. {
  246.     // We don't acquire it because we return it
  247.     ODShape* dragRgn = ::FW_NewODShape(ev, GetRectGeometry());
  248.  
  249.     ::FW_OutlineODShape(ev, dragRgn, GetPenSize());
  250.  
  251.     return dragRgn;
  252. }
  253.  
  254. //----------------------------------------------------------------------------------------
  255. // CTextShape::Flatten
  256. //----------------------------------------------------------------------------------------
  257.  
  258. void CTextShape::Flatten(FW_CWritableStream& archive)
  259. {    
  260.     CBoundedShape::Flatten(archive);
  261.     archive << fText;
  262. }
  263.  
  264. //----------------------------------------------------------------------------------------
  265. // CTextShape::Read
  266. //----------------------------------------------------------------------------------------
  267.  
  268. void* CTextShape::Read(FW_CReadableStream& stream, FW_ClassTypeConstant type)
  269. {
  270. FW_UNUSED(type);
  271.     // [HLX] This is a hack until I can register object with the archiver
  272.     CDrawReadableStream *drawArchive = (CDrawReadableStream*)&stream;
  273.     return FW_NEW(CTextShape, (drawArchive->GetDrawPart(), stream));
  274. }
  275.  
  276. //----------------------------------------------------------------------------------------
  277. // CTextShape::GetObjectClass
  278. //----------------------------------------------------------------------------------------
  279.  
  280. ODDescType CTextShape::GetObjectClass() const
  281. {
  282.     return cText;
  283. }
  284.  
  285.